package me.luochenyxh.base.util

import androidx.activity.ComponentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.alibaba.android.arouter.launcher.ARouter
import me.hgj.jetpackmvvm.util.LogUtils


/**
 *@创建者：XH-hua
 *@创建时间：2021/7/5 19:08
 *@描述：
 */
class YBaseActivityHelper(val activity: ComponentActivity) {
    var TAG: String = activity.javaClass.simpleName
    fun initAc() {
        activity.run {
            try {
                ARouter.getInstance().inject(this)
            } catch (e: Exception) {
                LogUtils.e("BaseActivity-[${TAG}]-ARouter-Exception:${e.printStackTrace()}")
            }
            lifecycle.addObserver(object : LifecycleObserver {
                @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
                fun onCreate() {
                    LogUtils.d("BaseActivity-[${TAG}]-onCreate")
//                    ActivityManager.pushActivity(activity)
                }
                @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
                 fun onPause() {
                    LogUtils.e("BaseActivity-[${TAG}]-onPause")
                }
                @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
                fun onStop() {
                    LogUtils.e("BaseActivity-[${TAG}]-onStop")
                }

                @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
                fun onDestroy() {
                    LogUtils.e("BaseActivity-[${TAG}]-onDestroy")
//                    ActivityManager.removeActivity(activity)
                    lifecycle.removeObserver(this)
                }
            })
        }
    }

}